<?php
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2012 Alexandre Vaillancourt                                  //
//                                                                            //
// Permission is hereby granted, free of charge, to any person obtaining a    //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation  //
// the rights to use, copy, modify, merge, publish, distribute, sublicense,   //
// and/or sell copies of the Software, and to permit persons to whom the      //
// Software is furnished to do so, subject to the following conditions:       //
//                                                                            //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software.                        //
//                                                                            //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        //
// DEALINGS IN THE SOFTWARE.                                                  //
////////////////////////////////////////////////////////////////////////////////

/**
 * Additionnal functions for the table/view views_on_page_at_tick
 * 
 * @author Alexandre Vaillancourt <alexandre.vaillancourt@gmail.com>
 * @license http://code.google.com/p/rappelz-hunbot/wiki/License MIT License
 * @copyright Copyright (c) 2012 Alexandre Vaillancourt
 * @since 
 * @package 
 */
 
include_once('class.views_on_page_at_tick.php');
class views_on_page_at_tick_suppelemented extends views_on_page_at_tick
{
	public function GetOldestViewsFromTime($in_page, $in_timestamp_type, $in_timestamp) {
		
		$connection = Database::Connect();
		$views_on_page_at_tickList = Array();
		
		switch($in_timestamp_type){
			case 'day': 
			case 'week': 
			case 'month': 
				$timestamp_type_column_name = $in_timestamp_type; 
				break;
			default:
				$timestamp_type_column_name = 'hour';
				break;
		}
		$timestamp_type_column_name = '`' . $timestamp_type_column_name . '_timestamp`';
		//hour_timestamp 	day_timestamp 	week_timestamp 	month_timestamp
		$page_id = $in_page->wiki_pageId;
		
		$this->pog_query = "SELECT * FROM `views_on_page_at_tick_with_tick_data` where $timestamp_type_column_name >= $in_timestamp AND `wiki_pageid` = $page_id ORDER BY $timestamp_type_column_name ASC LIMIT 1";
		
		$cursor = Database::Reader($this->pog_query, $connection);

		while ($row = Database::Read($cursor))
		{
			$views_on_page_at_tick = new views_on_page_at_tick_suppelemented;
			$views_on_page_at_tick->views_on_page_at_tickId = $row['views_on_page_at_tickid'];
			$views_on_page_at_tick->wiki_pageId = $row['wiki_pageid'];
			$views_on_page_at_tick->visit_tickId = $row['visit_tickid'];
			$views_on_page_at_tick->views = $this->Unescape($row['views']);
			$views_on_page_at_tickList[] = $views_on_page_at_tick;
		}
		return $views_on_page_at_tickList;
	}
}
?>